package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.GoodsTotalBean;
import com.project.mapper.IGoodsTotalMapper;
import com.project.service.IGoodsTotalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GoodsTotalServiceImpl implements IGoodsTotalService {

    @Autowired
    private IGoodsTotalMapper goodsTotalMapper;

    @Override
    public GoodsTotalBean findByItem(String name, String size, String color) {
        QueryWrapper<GoodsTotalBean> qw = new QueryWrapper<>();
        qw.eq("gt_name",name);
        qw.eq("gt_size",size);
        qw.eq("gt_color",color);

        return goodsTotalMapper.selectOne(qw);
    }

    @Override
    public void add(GoodsTotalBean goodsTotalBean) {
        goodsTotalMapper.insert(goodsTotalBean);
    }

    @Override
    public void update(Integer goodsTotalId, Integer deltaNum) {
        GoodsTotalBean goodsTotalBean = goodsTotalMapper.selectById(goodsTotalId);
        goodsTotalBean.setNum(goodsTotalBean.getNum()+deltaNum);
        goodsTotalMapper.updateById(goodsTotalBean);
    }


}
